﻿CREATE PROCEDURE [dbo].[LoopAndTruncate] 
	@TablePrefix Varchar(500)	
AS
BEGIN
declare @obj_ID varchar(50)
declare @TblName varchar(100)
declare @sqlString varchar(500)
select @obj_ID =  min( object_id ) from sys.tables where name like @TablePrefix


while @obj_ID is not null
begin
   
	select @obj_ID = min(object_id ) from sys.tables where name like @TablePrefix and object_ID > @obj_ID
	select @TblName = [name] from sys.tables where object_id = @obj_ID
	
	select @sqlString = 'truncate table ' + @TblName
	PRINT 'Working on '  + @TblName + ' - Executing:' + @sqlString
Exec (@sqlString)
end
END


